package org.labuladong;

/**
 * @Auther: qingle
 * @Date: 2024/9/12-5:45
 * @Description: 最简单的⼆分算法，旨在突出它的双指针特性：
 * @version: 1.0
 */
public class L01_binarySearch {

	int binarySearch(int[] nums, int target) {
		int left = 0;
		int right = nums.length - 1;
		while(left <= right) {
			int mid = (left + right)/2;
			if (nums[mid] == right) return mid;
			else if (nums[mid] <= right) left = mid + 1;
			else if (nums[mid] >= right) right = mid - 1;
		}
		return -1;
	}
}
